<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script>
    var add = function (args, fn, count) {
      let timer = null
      const action = function () {
        for (let i = 0; i < Math.min(count, args.length); i++) {
          fn(args.shift())
        }
      }
      return function () {
        timer = setInterval(() => {
          if (args.length === 0) {
            return clearInterval(timer)
          }
          action()
        }, 200)
      }
    }
    var args = [];
    for (let index = 0; index < 100; index++) {
      args.push(index);
    }
    var create = add(args, function (n) {
      var div = document.createElement('div');
      div.innerHTML = n;
      document.body.append(div);
    }, 8)
    create();
  </script>
</body>

</html>
